//引入常量
import { INCREMENTCOUNT, DECREMENTCOUNT } from '../constant/countConst'
const init = {
  count: 0
}


export default function countReducer(prevStata = init, action) {
  console.log('countReducer调用了');
  //console.log(action, 'action');
  //action是：
  // { type: 'increamentCount', data: 1 }
  // data: 1
  // type: "increamentCount"
  //判断action中的type
  //累加
  const { type, data } = action
  switch (type) {
    case INCREMENTCOUNT:
      return {
        ...init, count: prevStata.count + data
      }
  }
  //累减
  switch (type) {
    case DECREMENTCOUNT:
      return {
        ...init, count: prevStata.count - data
      }
  }
  return prevStata
}